package com.xuecheng.content.controller;

import com.xuecheng.commons.model.dto.TeachplanDto;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.model.vo.TeachplanVo;
import com.xuecheng.commons.utils.BeanHelper;
import com.xuecheng.content.domain.Teachplan;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 课程计划前端控制器
 * </p>
 *
 * @author itheima
 */
@Slf4j
@RestController
public class TeachplanController {

    @Autowired
    private TeachplanService  teachplanService;
    //查询课程计划
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public ResponseResult<TeachplanVo> treeNodes(@PathVariable("courseId") Long id){
        //调用service并返回
       return teachplanService.treeNodes(id);
    }
    //新增或修改课程内容（章节，小节）
    @PostMapping("/teachplan")
    public ResponseResult saveOrUpdateTeachplan(@RequestBody TeachplanDto dto) {
        return teachplanService.saveOrUpdateTeachplan(dto);
    }
    // 删除课程计划
    @DeleteMapping("/teachplan/{id}")
    public ResponseResult deleteTeachplan(@PathVariable("id") Long teachplanId) {
        return teachplanService.deleteTeachplan(teachplanId);
    }
    // 根据id查询课程计划
    @GetMapping("/teachplan/{teachplanId}")
    public ResponseResult<TeachplanVo> findTechplanById(@PathVariable("teachplanId")Long teachplanId){
        // 1.直接查询
        Teachplan teachplan = teachplanService.getById(teachplanId);
        // 2.转vo
        TeachplanVo vo = BeanHelper.copyProperties(teachplan, TeachplanVo.class);
        // 3.返回
        return ResponseResult.okResult(vo);
    }
}
